package com.data.modules.sm.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.data.common.util.ConvertUtils;
import com.data.common.util.IPUtils;
import com.data.common.util.SpringContextUtils;
import com.data.modules.sm.entity.SmScreenAuth;
import com.data.modules.sm.mapper.SmScreenAuthMapper;
import com.data.modules.sm.service.ISmScreenAuthService;
import com.data.modules.system.entity.SysPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 大屏授权表
 * @Author: data-boot
 * @Date:   2022-11-16
 * @Version: V1.0
 */
@Service
public class SmScreenAuthServiceImpl extends ServiceImpl<SmScreenAuthMapper, SmScreenAuth> implements ISmScreenAuthService {

    @Autowired
    private SmScreenAuthMapper mapper;
    /**
     * 校验登录ip 地址是否授权
     * @param province
     * @return
     */
    @Override
    public Integer getScreenAuth(String province) {
        Integer i = 0;
        String ip =IPUtils.getIpAddr(SpringContextUtils.getHttpServletRequest());
        if(ObjectUtil.isNotEmpty(ip)){
            LambdaQueryWrapper<SmScreenAuth> query = new LambdaQueryWrapper<SmScreenAuth>();
            query.eq(SmScreenAuth::getIp,ip);
            query.le(SmScreenAuth::getStartTime,new Date());
            query.ge(SmScreenAuth::getEndTime,new Date());
            i = mapper.selectList(query).size();

        }
        return i;
    }
}
